package com.cyl.manager.lbs.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cyl.manager.lbs.mapper.LbsDtxqMapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.livesass.QuizRecordService;
import com.ruoyi.vo.QuizStatisticsVo;
import com.volcengine.model.livesaas.response.ListQuizStatisticsAPIResponse.QuizStatisticsAPI;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
 * 直播列表Controller
 *
 * @author zcc
 * @date 2025-02-09
 */
@Api(description ="直播问答接口列表")
@RestController
@RequestMapping("/mall/lbsDtxq")
public class LbsDtxqController extends BaseController {

	@Autowired
    private LbsDtxqMapper lbsDtxqMapper;
    @Autowired
    private QuizRecordService quizRecordService;
    
    @ApiOperation("获取答题总条数")
    @PreAuthorize("@ss.hasPermi('mall:lbsDtxq:getCount')")
    @GetMapping(value = "/getCount")
    public ResponseEntity<Integer> getCount(Long zbjlid,Long quizid) {
        return ResponseEntity.ok(quizRecordService.getPageTotalCount(zbjlid, quizid));
    }

    @ApiOperation("获取直播问题列表")
    @PreAuthorize("@ss.hasPermi('mall:lbsDtxq:getQs')")
    @GetMapping(value = "/getQs")
    public ResponseEntity<List<QuizStatisticsAPI>> getQs(Long zbjlid) {
        return ResponseEntity.ok(quizRecordService.listQuizStatisticsAPI(zbjlid));
    }
    
    @ApiOperation("获取直播列表详细信息")
    @PreAuthorize("@ss.hasPermi('mall:lbsDtxq:save')")
    @GetMapping(value = "/save")
    public ResponseEntity<Integer> save(Long zbjlid,Long quizid,Integer pageNo) {
    	List<QuizStatisticsVo> list = quizRecordService.listQuizRecordAPI(zbjlid, quizid, pageNo);
    	if(list!=null && list.size()>0) {
    		saveLbsDtxqs(list, zbjlid, quizid);
    	}
        return ResponseEntity.ok(list.size());
    }
     
    @Transactional
    private void saveLbsDtxqs(List<QuizStatisticsVo> list,Long zbjlid,Long quizid) {
    	lbsDtxqMapper.saveLbsDtxqs(list);
		lbsDtxqMapper.setDeptxx(zbjlid, quizid);
    }
    
}
